<template>
    <div class="dialog">
        <el-dialog :title="dialog.title" :visible.sync="dialog.show" :close-on-click-modal='false' :close-on-press-escape='false'
            :modal-append-to-body="false">
            <div class="form">
                <el-form ref="form" :model="formData" :rules="form_rules" label-width="120px"
                    style="margin:10px;width:auto">
                    <el-form-item label="标题" prop="title">
                        <el-input type="title" v-model="formData.Intitle"></el-input>
                    </el-form-item>
                    <el-form-item label="内容" prop="content">
                        <el-input type="textarea" v-model="formData.ChXin"></el-input>
                    </el-form-item>
                    <el-form-item class="text_right">
                        <el-button @click="dialog.show=false">取消</el-button>
                        <el-button type="primary" @click="onSubmit('form')">提交</el-button>
                    </el-form-item>
                </el-form>

            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                
                form_rules: {
                    Intitle: [
                        { required: true, message: '标题不能为空', trigger: 'blur' }
                    ],
                    ChXin: [
                        { required: true, message: '标题不能为空', trigger: 'blur' }
                    ]
                }
            }
        },
        props: {
            dialog: Object,
            formData: Object
        },
        mounted(){
            //  console.info(this.router.formData)
            //  this.onSubmit(this.router.formData)
             
        },
        methods: {

            onSubmit(form) {

                this.$refs[form].validate(valid => {
                    if (valid) { 

                        const url=this.dialog.option=="add" ? "add" : "edit";
                         this.axios({
                             method: 'post',
                             url: `http://127.0.0.1:3000/api/postconsult/${url}`,
                             // headers:{
                             //    'Content_type':'application/x-www-form-urlencoded'
                             // },
                            data: {
                                Contitle: this.formData.Intitle,
                                ZiContent: this.formData.ChXin,
                                Zid:this.formData.id
                            }
                        })

                            .then(res => {
                                this.$message({
                                    message: '成功',
                                    type: 'success',
                                    
                                })
                                this.dialog.show = false;
                                console.log(this.formData);

                                this.$router.go(0);
                            })
                            .catch(err =>{
                                console.log(err)
                            })

                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>